﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataControl;
using System.Data;
using System.Text;

namespace ATW.MT.BUS
{
    public class bus_C_Pressure
    {
        DataAccess da = null;
        public bus_C_Pressure()
        {
            da = new DataAccess();
        }
        #region 方法
        /// <summary>
        /// 压力等级分页查询
        /// </summary>
        /// <param name="name"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public DataTable PressPagerQuery(string name, int page, int pagesize)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append(@"select top 100 percent * from C_PressureLevel where 1=1");
            if (!String.IsNullOrEmpty(name))
            {
                sql.Append(" and Pressure_Code_C like '%" + name + "%' or Pressure_Code_S like '%" + name + "%'");
            }
            sql.Append(" order by Pressure_Code_C,Pressure_Code_S");
            return da.PageSize(sql.ToString(), page, pagesize, "PressureID","create_time desc");
        }
        public DataTable PressQuery(string ProductionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select P.* from T_Production_Pressure PP
                                    left join C_PressureLevel P on PP.PressureID=P.PressureID
                                    where PP.ProductionID='{0}' order by P.Pressure_Code_C desc", ProductionID);
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 新增压力等级
        /// </summary>
        /// <param name="code_c"></param>
        /// <param name="code_s"></param>
        /// <returns></returns>
        public int PressureAdd(string code_c, string code_s, string rate)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into C_PressureLevel(Pressure_Code_C,Pressure_Code_S,[Pressure_rate])
                        values('{0}','{1}','{2}')", code_c, code_s, rate);
            return da.ExcuteNoQuery(sql.ToString());
        }
        /// <summary>
        /// 修改压力等级
        /// </summary>
        /// <param name="code_c"></param>
        /// <param name="code_s"></param>
        /// <param name="pid"></param>
        /// <returns></returns>
        public int PressureEdit(string code_c, string code_s, string rate, string pid)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"update C_PressureLevel set Pressure_Code_C='{0}',Pressure_Code_S='{1}',[Pressure_rate]='{3}' 
                        where PressureID='{2}'", code_c, code_s, pid, rate);
            return da.ExcuteNoQuery(sql.ToString());
        }
        /// <summary>
        /// 压力等级是否存在
        /// </summary>
        /// <param name="code_c"></param>
        /// <param name="code_s"></param>
        /// <returns></returns>
        public bool IsPressExist(string code_c, string code_s)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select * from C_PressureLevel where Pressure_Code_C='{0}' and Pressure_Code_S='{1}'", code_c, code_s);
            DataTable dt = da.ExecuteDataTable(sql.ToString());
            if (dt != null && dt.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        #endregion
    }
}